package com.laoxu.test.rbacdemo.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 控制层通用结果集
 */
@Data
public class Result implements Serializable {

	private int code;
	private boolean success; // 成功标识
	private String msg;
	private Object data;

	public static Result ok(){
		return ok(200,"",null);
	}

	public static Result ok(String msg,Object data){
		return ok(200,msg,data);
	}


	public static Result ok(String msg){
		return ok(200,msg,null);
	}

	/**
	 * 抽取结果集，提高代码重用性
	 * @param data
	 * @return ok(code,msg,data)
	 */
	public static Result ok(Object data){
		return ok(200,"操作成功",data);
	}

	/**
	 * 抽取结果集,提搞代码重用性
	 * @param msg
	 * @return error(code,msg,null)
	 */
	public static Result error(String msg){
		return error(400,msg);
	}

	/**
	 * 返回成功获取的结果集
	 * @param code
	 * @param msg
	 * @param data
	 * @return result
	 */
	public static Result ok(int code,String msg,Object data){
		Result result = new Result();
		result.setSuccess(true);
		result.setCode(code);
		result.setMsg(msg);
		result.setData(data);
		return result;
	}

	/**
	 * 返回错误（不带数据）
	 * @param code
	 * @param msg
	 * @return
	 */
	public static Result error(int code,String msg){
		Result result = new Result();
		result.setCode(code);
		result.setSuccess(false);
		result.setMsg(msg);
		return result;
	}


}
